function isWx() {
    let reg = /micromessenger/i;
    return reg.test(window.navigator.userAgent)
}

function isAli() {
    let reg = /alipay/i;
    return reg.test(window.navigator.userAgent)
}

function isQQ() {
    let reg = /QQ\//;
    return reg.test(window.navigator.userAgent)
}

function needMask() {
    return isWx() || isAli() || isQQ()
}

(function () {
    /**
     * 进入对应语言页面
     */

    let language = 'en'

    if (navigator.language) {
        language = navigator.language
    } else if (navigator.browserLanguage) {
        language = navigator.browserLanguage
    }

    if (window.location.search.split('?')[1] === 'lang=en') {
        language = 'en'
    }

    language = language.toLowerCase()

    /**
     * 目前支持两种语言
     * 1. 如果是中文则显示zh-cn , 对应cn
     * 2. 其他情况均采用en, 对应us
     * */
    if (language.indexOf('zh') === 0) {
        language = '/cn'
    } else {
        language = '/us'
    }

    if (window.location.pathname.indexOf(language) !== 0) {
        window.location.pathname = `${language}/download.html`
    }

})()










function downloadApp(canBeDownloaded, type) {
    if (canBeDownloaded) {
        if (type === 'ios') {
            window.location.href = 'itms-services:///?action=download-manifest&url=https://m.quickdax.com/QuickDax/QuickDax.plist'
        } else {
            window.location.href = 'https://m.quickdax.com/QuickDax/Android/QuickDax.apk'
        }
    } else {
        $('#mask').show()
    }
}

$(function () {
    // 显示遮罩
    if (needMask()) {
        $('#mask').show()
    }

    // 关闭遮罩
    $('#mask-close').click(function () {
        $('#mask').hide()
    })


    // ios下载
    $('#ios').click(function () {
        downloadApp(!needMask(), 'ios')
    })
    // android下载
    $('#android').click(function () {
        downloadApp(!needMask(), 'android')
    })
});
